package com.atguigu.jxc.controller;

import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/customer")
public class CustomerCrotroller {

    @Autowired
    private CustomerService customerService;

    @PostMapping("/list")
    public String list(HttpServletRequest request){
        //System.out.println("hhhhh");
        Integer page = Integer.valueOf(request.getParameter("page"))-1;
        Integer rows = Integer.valueOf(request.getParameter("rows"));
        String customerName = request.getParameter("customerName");
        String result = customerService.getList(page,rows,customerName);
        return result;
    }

    @PostMapping("/save")
    public String save(Customer customer, @RequestParam(required = false) String customerId){

        return customerService.save(customer,customerId);
    }

    @PostMapping("delete")
    public String delete(@RequestParam(value = "ids")String[] ids){
        return customerService.delete(ids);
    }
}
